package org.xxd.kafka.clients.common.network;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.channels.ScatteringByteChannel;

/**
 * @author: XiaoDong.Xie
 * @create: 2020-09-28 10:09
 * @description:
 */
public class NetworkReceive implements Receive {

    private static final Logger log = LoggerFactory.getLogger(NetworkReceive.class);

    public final static String UNKNOWN_SOURCE = "";
    public final static int UNLIMITED = -1;

    private final ByteBuffer size;
    private final String source;

    private final int maxSize;
    private ByteBuffer buffer;


    public NetworkReceive(String source, ByteBuffer buffer) {
        this.source = source;
        this.buffer = buffer;
        this.size = null;
        this.maxSize = UNLIMITED;
    }

    public NetworkReceive(String source) {
        this.source = source;
        this.size = ByteBuffer.allocate(4);
        this.buffer = null;
        this.maxSize = UNLIMITED;
    }

    public NetworkReceive(int maxSize, String source) {
        this.source = source;
        this.size = ByteBuffer.allocate(4);
        this.buffer = null;
        this.maxSize = maxSize;
    }

    public NetworkReceive() {
        this(UNKNOWN_SOURCE);
    }

    @Override
    public String source() {
        return source;
    }


    @Override
    public boolean complete() {
        return false;
    }

    @Override
    public long readFrom(ScatteringByteChannel channel) throws IOException {
        return 0;
    }

    public Buffer payload() {
        return null;
    }
}
